import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import soot.Unit;

/**
 * this class is the basic path node along the path during static analysis
 * 
 * @author Steven Hsui
 * 
 */
public class StaticNode {

	private boolean isCallPoint;
	private boolean isCallPoint2;
	private Unit unit;
	private int level;
	private String className;

	public StaticNode(Unit current, boolean callPoint, int level,
			String className) {
		this.unit = current;
		this.isCallPoint2 = this.isCallPoint = callPoint;
		this.level = level;
		this.className = className;
	}

	public boolean isCallPoint() {
		return this.isCallPoint;
	}

	public Unit getUnit() {
		return this.unit;
	}

	public int getLevel() {
		return this.level;
	}

	public String getClassName() {
		return this.className;
	}

//	public StaticNode clone() {
//		StaticNode clone = new StaticNode(this.unit, this.isCallPoint,
//				this.level, this.className);
//		return clone;
//	}

	public void setIsCallPoint(boolean isCallPoint) {
		this.isCallPoint = isCallPoint;
	}

	@Override
	public boolean equals(Object node) {
		if (!(node instanceof StaticNode)) {
			return false;
		}
		StaticNode snode = (StaticNode) node;
		if ((snode.isCallPoint() == this.isCallPoint())
				&& (snode.getUnit() == this.getUnit())) {
			return true;
		}
		return false;
	}

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer("");
		int classNum = -2;

		if (this.getUnit().getTags().isEmpty()) {
			sb.append("empty " + this.className);
		} else {
			classNum = ClassNameIndex.getClassNum(this.className);
			sb.append(classNum + "::"
					+ this.getUnit().getTags().get(0).toString());
		}
		return sb.toString();
	}

	public boolean isCallPoint2() {
		return this.isCallPoint2;
	}

	public boolean similar(StaticNode staticNode) {
		if (this.toString().equals(staticNode.toString())) {
			return true;
		}
		return false;
	}

	public String getLine() {
		return this.getUnit().getTags().get(0).toString();
	}

}